package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.PurchaseList;
import com.atguigu.jxc.entity.ReturnList;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.ReturnListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("returnListGoods")
public class ReturnListGoodsController {
    @Autowired
    private ReturnListService returnListService;
    @PostMapping("save")
    public ServiceVO save(@RequestParam String returnNumber, ReturnList returnList, String returnListGoodsStr, HttpServletRequest request){
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("currentUser");
        returnList.setReturnNumber(returnNumber);
        returnList.setUserId(user.getUserId());
        return returnListService.save(returnList,returnListGoodsStr);
    }
   // http://localhost:8080/returnListGoods/list
   @RequestMapping("list")
   public Map<String,Object> list(String returnNumber, Integer supplierId, Integer state, String sTime, String eTime) {
       return returnListService.list(returnNumber,supplierId,state,sTime,eTime);
   }
    @RequestMapping("goodsList")
    public Map<String,Object> goodsList(Integer returnListId) {
        return returnListService.goodsList(returnListId);
    }
    @RequestMapping("delete")
    public ServiceVO deleteByReturnListId(Integer returnListId){
        return returnListService.deleteByReturnListId(returnListId);
    }

}
